package edu.nf.exam.service.impl;

import com.github.pagehelper.PageInfo;
import edu.nf.exam.dao.ExamPaperResultInfoDao;
import edu.nf.exam.dao.impl.ExamPaperResultInfoDaoImpl;
import edu.nf.exam.entity.ExamPaperResultInfo;
import edu.nf.exam.exception.DataAcessException;
import edu.nf.exam.service.ExamPaperResultService;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 试卷结果表--业务接口实现类
 */
public class ExamPaperResultServiceImpl implements ExamPaperResultService {

    /**
     * 添加
     * @param examPaperResultInfo
     */
    @Override
    public void add(ExamPaperResultInfo examPaperResultInfo) {
        ExamPaperResultInfoDao dao=new ExamPaperResultInfoDaoImpl();
        try {
            dao.add(examPaperResultInfo);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("添加失败");
        }
    }

    /**
     * 查询
     * @param examPaperResultInfo
     * @return
     */
    @Override
    public List<ExamPaperResultInfo> select(ExamPaperResultInfo examPaperResultInfo) {
        ExamPaperResultInfoDao dao=new ExamPaperResultInfoDaoImpl();
        try {
            List<ExamPaperResultInfo> list = dao.select(examPaperResultInfo);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("查询失败");
        }
    }

    /**
     * 分页查询
     * @param userName
     * @param examPaperName
     * @param levelName
     * @param subjectName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<ExamPaperResultInfo> selectByPage(String userName, String examPaperName, String levelName ,String subjectName, Integer pageNum, Integer pageSize) {
        List<ExamPaperResultInfo> list = new ExamPaperResultInfoDaoImpl().selectByPage(userName, examPaperName, levelName ,subjectName, pageNum, pageSize);
        PageInfo<ExamPaperResultInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 根据试卷ID查询成绩名次
     * @param examPaperId
     * @return
     */
    @Override
    public List<ExamPaperResultInfo> selectRankByExamPaperId(Integer examPaperId) {
        List<ExamPaperResultInfo> list = new ExamPaperResultInfoDaoImpl().selectRankByExamPaperId(examPaperId);
        return list;
    }
}
